﻿using HuaweiCloud.Dotnet.Samples.DMS4RabbitMQ.Message;
using MassTransit;
using Newtonsoft.Json;

namespace HuaweiCloud.Dotnet.Samples.DMS4RabbitMQ.Consumer
{
    /// <summary>
    /// 定义消费者
    /// </summary>
    public class HelloDMSConsumer : IConsumer<IHelloDMS>
    {
        private readonly ILogger _logger;
        public HelloDMSConsumer(ILogger<HelloDMSConsumer> logger)
        {
            _logger = logger;
        }
        public Task Consume(ConsumeContext<IHelloDMS> context)
        {
            // 获取消息体
            var msg = context.Message;
            // 把消息体序列化成json字符串，并打印到控制台
            _logger.LogInformation("Received:{msg}", JsonConvert.SerializeObject(msg));
            return Task.CompletedTask;
        }
    }
}
